#ifndef _DECODEDSF_H_
#define _DECODEDSF_H_

#include "DecodeDSDFile.h"

class DecodeDSF : public DecodeDSDFile
{
public:
    virtual ~DecodeDSF(void);
    bool open(const std::string& file_name, double seek_seconds = 0.0);
    // Data is returned with the LSB first. god knows what LSB means for 1 bit audio.
    uint64_t read(uint8_t* out, uint64_t size);
    // Copy ID3v2 metacata into the buf of size buf_size. decoder is invalid afterwards.
    bool extractID3(uint8_t* buf, int buf_size);
    
private:
    struct ChunkDSD {
	uint8_t id[4];
	uint64_t chunk_size;
	uint64_t total_size;
	uint64_t metadata_ptr;
    } __attribute__ ((packed));

    struct ChunkFMT {
	uint8_t id[4];
	uint64_t chunk_size;
	uint32_t version;
	uint32_t format_id;
	uint32_t channel_type;
	uint32_t channel_count;
	uint32_t frequency;
	uint32_t bits_per_sample;
	uint64_t sample_count;
	uint32_t block_size_per_channel;
	uint32_t reserved;
    } __attribute__ ((packed));

    struct ChunkDATA {
	uint8_t id[4];
	uint64_t chunk_size; // Includes the data size. data size = chunk_size - 12;
	// .. Data comes here
    } __attribute__ ((packed));
    
    int file_ = -1;
    ChunkDSD dsd_;
    ChunkFMT fmt_;
    ChunkDATA data_;
    uint64_t data_left_;
};

#endif
